﻿Imports System.Data.SqlClient
Public Class dbSales
    Dim Var As New varDeclare

    Public Function GetBaseList() As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT DISTINCT [Number], [SO Date], [PO / Reference], [Customer], [Request Delivery Date], [Sales], [Status] FROM v_SalesOrderList WHERE COMP = @Comp ORDER BY Number DESC"
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function GetQuotationList() As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT Number, [Offer Date], Customer, Client, [Validity Date], Curr, [Sub Total] FROM v_QuotationList WHERE COMP = @Comp ORDER BY Number DESC"
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function LastNumberQuotation(Period As String) As String
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT Number FROM v_LastNumberQuotation WHERE COMP = @Comp AND Period = @Period"
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        command.Parameters.Add("@Period", SqlDbType.VarChar).Value = Period
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Dim str As String = Convert.ToString(result)
        If (str = "") Then
            str = "0001"
        End If
        Return str
    End Function

    Public Function GetItemList() As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT * FROM SALES_PRICE"
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function GetQuotationLine(Number As String) As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT * FROM v_GetQuotationLine WHERE COMP = @Comp AND Number = @Number ORDER BY Seq"
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        command.Parameters.Add("@Number", SqlDbType.VarChar).Value = Number
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function GetSampleRequestList() As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT NUMBER,DATE,CUSTOMER,CONTACT,CODE,DESCRIPTION,REQUEST,DELIVERED,[SALES NAME],STATUS FROM v_ListSampleRequest WHERE COMP = @Comp ORDER BY Number DESC"
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function GetSampleRequestDetail(Number As String) As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "GetSampleRequestDetail"
        command.Parameters.Add("@Number", SqlDbType.VarChar).Value = Number
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function LastNumberSampleRequest(Period As String) As String
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT Number FROM v_LastNumberSampleRequest WHERE COMP = @Comp AND Period = @Period"
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        command.Parameters.Add("@Period", SqlDbType.VarChar).Value = Period
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Dim str As String = Convert.ToString(result)
        If (str = "") Then
            str = "0001"
        End If
        Return str
    End Function

    Public Function SaveQuotation(ByVal Number As String, ByVal DocDate As String, ByVal CustCode As String, _
                                        ByVal Office As String, ByVal Phone As String, ByVal Fax As String, _
                                        ByVal AttentSal As String, ByVal AttentName As String, ByVal Email As String, _
                                        ByVal ValidDate As String, ByVal DocCurr As String, ByVal Type As String, _
                                        ByVal SubTotal As Decimal, ByVal Reff As String, ByVal ReffDate As String, _
                                        ByVal Incoterms As String, ByVal Terms As String, ByVal UserID As String, _
                                        ByVal PriceType As String, ByVal Payment As String, ByVal Rev As String) As String
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_SaveQuotation"
        command.Parameters.Add("@Number", SqlDbType.VarChar).Value = Number
        command.Parameters.Add("@DocDate", SqlDbType.VarChar).Value = DocDate
        command.Parameters.Add("@CustCode", SqlDbType.VarChar).Value = CustCode
        command.Parameters.Add("@Office", SqlDbType.VarChar).Value = Office
        command.Parameters.Add("@Phone", SqlDbType.VarChar).Value = Phone
        command.Parameters.Add("@Fax", SqlDbType.VarChar).Value = Fax
        command.Parameters.Add("@AttentSal", SqlDbType.VarChar).Value = AttentSal
        command.Parameters.Add("@AttentName", SqlDbType.VarChar).Value = AttentName
        command.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email
        command.Parameters.Add("@ValidDate", SqlDbType.VarChar).Value = ValidDate
        command.Parameters.Add("@DocCurr", SqlDbType.VarChar).Value = DocCurr
        command.Parameters.Add("@SubTotal", SqlDbType.Decimal).Value = SubTotal
        command.Parameters.Add("@Reff", SqlDbType.VarChar).Value = Reff
        command.Parameters.Add("@ReffDate", SqlDbType.VarChar).Value = ReffDate
        command.Parameters.Add("@Incoterms", SqlDbType.VarChar).Value = Incoterms
        command.Parameters.Add("@Terms", SqlDbType.VarChar).Value = Terms
        command.Parameters.Add("@UserID", SqlDbType.VarChar).Value = UserID
        command.Parameters.Add("@PriceType", SqlDbType.VarChar).Value = PriceType
        If (Payment <> "") Then
            command.Parameters.Add("@Payment", SqlDbType.VarChar).Value = Payment
        Else
            command.Parameters.Add("@Payment", SqlDbType.VarChar).Value = DBNull.Value
        End If
        command.Parameters.Add("@Rev", SqlDbType.VarChar).Value = Rev
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        command.Parameters.Add("@Type", SqlDbType.VarChar).Value = Type
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Return Convert.ToString(result)
    End Function

    Public Function SaveQuotationLine(ByVal Number As String, ByVal DocDate As String, ByVal CustCode As String, _
                                        ByVal Groups As String, ByVal Code As String, ByVal TS As String, _
                                        ByVal item_desc As String, ByVal Curr As String, ByVal UnitPrice As String, _
                                        ByVal UnitDisc As String, ByVal UnitNetPrice As String, ByVal UnitUOM As String, _
                                        ByVal UnitQty As Decimal, ByVal UnitPriceAmount As String, ByVal UnitNotes As String, _
                                        ByVal Seq As String, ByVal UserID As String) As Boolean
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_SaveQuotationLine"
        command.Parameters.Add("@Number", SqlDbType.VarChar).Value = Number
        command.Parameters.Add("@DocDate", SqlDbType.VarChar).Value = DocDate
        command.Parameters.Add("@CustCode", SqlDbType.VarChar).Value = CustCode
        command.Parameters.Add("@Groups", SqlDbType.VarChar).Value = Groups
        command.Parameters.Add("@Code", SqlDbType.VarChar).Value = Code
        command.Parameters.Add("@TS", SqlDbType.VarChar).Value = TS
        command.Parameters.Add("@item_desc", SqlDbType.VarChar).Value = item_desc
        command.Parameters.Add("@Curr", SqlDbType.VarChar).Value = Curr
        command.Parameters.Add("@UnitPrice", SqlDbType.Decimal).Value = CDec(UnitPrice)
        command.Parameters.Add("@UnitDisc", SqlDbType.Decimal).Value = CDec(UnitDisc)
        command.Parameters.Add("@UnitNetPrice", SqlDbType.Decimal).Value = CDec(UnitNetPrice)
        command.Parameters.Add("@UnitUOM", SqlDbType.VarChar).Value = UnitUOM
        command.Parameters.Add("@UnitQty", SqlDbType.Decimal).Value = CDec(UnitQty)
        command.Parameters.Add("@UnitPriceAmount", SqlDbType.Decimal).Value = CDec(UnitPriceAmount)
        command.Parameters.Add("@UnitNotes", SqlDbType.VarChar).Value = UnitNotes
        command.Parameters.Add("@Seq", SqlDbType.VarChar).Value = Seq
        command.Parameters.Add("@UserID", SqlDbType.VarChar).Value = UserID
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Return Convert.ToBoolean(result)
    End Function

    Public Function TransactionSalesManage(QuotationCode As Object, CustomerPO As Object, DateCustomerPO As Object, SampleRequestCode As Object, SalesOrderCode As Object) As String
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_TransactionSales"
        command.Parameters.Add("@QuotationCode", SqlDbType.VarChar).Value = QuotationCode
            command.Parameters.Add("@CustomerPO", SqlDbType.VarChar).Value = CustomerPO
            command.Parameters.Add("@DateCustomerPO", SqlDbType.VarChar).Value = DateCustomerPO
        command.Parameters.Add("@SampleRequestCode", SqlDbType.VarChar).Value = SampleRequestCode
        command.Parameters.Add("@SalesOrderCode", SqlDbType.VarChar).Value = SalesOrderCode
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Return Convert.ToString(result)
    End Function

    Public Function TransactionSalesStatus(QuotationCode As String) As DataTable
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT * FROM v_TransactionSales WHERE COMP = @Comp AND QuotationCode = @QuotationCode"
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        command.Parameters.Add("@QuotationCode", SqlDbType.VarChar).Value = QuotationCode
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds.Tables(0)
    End Function

    Public Function LastNumberSalesOrder(Period As String) As String
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT Number FROM v_LastNumberSalesOrder WHERE COMP = @Comp AND Period = @Period"
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        command.Parameters.Add("@Period", SqlDbType.VarChar).Value = Period
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Dim str As String = Convert.ToString(result)
        If (str = "") Then
            str = "0001"
        End If
        Return str
    End Function

    Public Function GetSalesOrderLine(Number As String) As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT * FROM v_GetSalesOrderLine WHERE COMP = @Comp AND Number = @Number ORDER BY Seq"
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        command.Parameters.Add("@Number", SqlDbType.VarChar).Value = Number
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function SaveSalesOrder(ByVal QuotationNumber As String, ByVal Number As String, ByVal DocDate As String, _
                                        ByVal CustCode As String, ByVal CPONumber As String, ByVal CPODate As String, _
                                        ByVal InvoiceAddress As String, ByVal InvoiceCity As String, ByVal InvoiceZip As String, _
                                        ByVal InvoiceCountry As String, ByVal InvoicePhone As String, ByVal InvoiceFax As String, _
                                        ByVal DeliveryAddress As String, ByVal DeliveryCity As String, ByVal DeliveryZip As String, _
                                        ByVal DeliveryCountry As String, ByVal DeliveryPhone As String, ByVal DeliveryFax As String, _
                                        ByVal SONotes As String, ByVal SOVAT As String, ByVal DocCurr As String, _
                                        ByVal SubTotal As Decimal, ByVal VatAmount As Decimal, ByVal ChargeAmount As Decimal, _
                                        ByVal GrandTotal As Decimal, ByVal AttentSal As String, ByVal AttentName As String, _
                                        ByVal Email As String, ByVal Incoterms As String, ByVal Terms As String, _
                                        ByVal UserID As String, ByVal SOType As String, ByVal Rev As String, _
                                        ByVal Type As String) As String
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_SaveSalesOrder"
        command.Parameters.Add("@QuotationNumber", SqlDbType.VarChar).Value = QuotationNumber
        command.Parameters.Add("@Number", SqlDbType.VarChar).Value = Number
        command.Parameters.Add("@DocDate", SqlDbType.VarChar).Value = DocDate
        command.Parameters.Add("@CustCode", SqlDbType.VarChar).Value = CustCode
        command.Parameters.Add("@CPONumber", SqlDbType.VarChar).Value = CPONumber
        command.Parameters.Add("@CPODate", SqlDbType.VarChar).Value = CPODate
        command.Parameters.Add("@InvoiceAddress", SqlDbType.VarChar).Value = InvoiceAddress
        command.Parameters.Add("@InvoiceCity", SqlDbType.VarChar).Value = InvoiceCity
        command.Parameters.Add("@InvoiceZip", SqlDbType.VarChar).Value = InvoiceZip
        command.Parameters.Add("@InvoiceCountry", SqlDbType.VarChar).Value = InvoiceCountry
        command.Parameters.Add("@InvoicePhone", SqlDbType.VarChar).Value = InvoicePhone
        command.Parameters.Add("@InvoiceFax", SqlDbType.VarChar).Value = InvoiceFax
        command.Parameters.Add("@DeliveryAddress", SqlDbType.VarChar).Value = DeliveryAddress
        command.Parameters.Add("@DeliveryCity", SqlDbType.VarChar).Value = DeliveryCity
        command.Parameters.Add("@DeliveryZip", SqlDbType.VarChar).Value = DeliveryZip
        command.Parameters.Add("@DeliveryCountry", SqlDbType.VarChar).Value = DeliveryCountry
        command.Parameters.Add("@DeliveryPhone", SqlDbType.VarChar).Value = DeliveryPhone
        command.Parameters.Add("@DeliveryFax", SqlDbType.VarChar).Value = DeliveryFax
        command.Parameters.Add("@SONotes", SqlDbType.VarChar).Value = SONotes
        command.Parameters.Add("@SOVAT", SqlDbType.VarChar).Value = SOVAT
        command.Parameters.Add("@DocCurr", SqlDbType.VarChar).Value = DocCurr
        command.Parameters.Add("@SubTotal", SqlDbType.Decimal).Value = SubTotal
        command.Parameters.Add("@VatAmount", SqlDbType.Decimal).Value = VatAmount
        command.Parameters.Add("@ChargeAmount", SqlDbType.Decimal).Value = ChargeAmount
        command.Parameters.Add("@GrandTotal", SqlDbType.Decimal).Value = GrandTotal
        command.Parameters.Add("@AttentSal", SqlDbType.VarChar).Value = AttentSal
        command.Parameters.Add("@AttentName", SqlDbType.VarChar).Value = AttentName
        command.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email
        command.Parameters.Add("@Incoterms", SqlDbType.VarChar).Value = Incoterms
        command.Parameters.Add("@Terms", SqlDbType.VarChar).Value = Terms
        command.Parameters.Add("@UserID", SqlDbType.VarChar).Value = UserID
        command.Parameters.Add("@SOType", SqlDbType.VarChar).Value = SOType
        command.Parameters.Add("@Rev", SqlDbType.VarChar).Value = Rev
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        command.Parameters.Add("@Type", SqlDbType.VarChar).Value = Type
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Return Convert.ToString(result)
    End Function

    Public Function SaveSalesOrderLine(ByVal CustCode As String, ByVal DocDate As String, ByVal Number As String, _
                                        ByVal Groups As String, ByVal Code As String, ByVal item_desc As String, _
                                        ByVal Curr As String, ByVal UnitPrice As String, ByVal UnitDisc As String, _
                                        ByVal UnitNetPrice As String, ByVal UnitUOM As String, ByVal UnitQty As String, _
                                        ByVal UnitPriceAmount As Decimal, ByVal DeliveryTime As String, ByVal UserID As String) As Boolean
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_SaveSalesOrderLine"
        command.Parameters.Add("@CustCode", SqlDbType.VarChar).Value = CustCode
        command.Parameters.Add("@DocDate", SqlDbType.VarChar).Value = DocDate
        command.Parameters.Add("@Number", SqlDbType.VarChar).Value = Number
        command.Parameters.Add("@Groups", SqlDbType.VarChar).Value = Groups
        command.Parameters.Add("@Code", SqlDbType.VarChar).Value = Code
        command.Parameters.Add("@item_desc", SqlDbType.VarChar).Value = item_desc
        command.Parameters.Add("@Curr", SqlDbType.VarChar).Value = Curr
        command.Parameters.Add("@UnitPrice", SqlDbType.Decimal).Value = CDec(UnitPrice)
        command.Parameters.Add("@UnitDisc", SqlDbType.Decimal).Value = CDec(UnitDisc)
        command.Parameters.Add("@UnitNetPrice", SqlDbType.Decimal).Value = CDec(UnitNetPrice)
        command.Parameters.Add("@UnitUOM", SqlDbType.VarChar).Value = UnitUOM
        command.Parameters.Add("@UnitQty", SqlDbType.Decimal).Value = CDec(UnitQty)
        command.Parameters.Add("@UnitPriceAmount", SqlDbType.Decimal).Value = CDec(UnitPriceAmount)
        command.Parameters.Add("@DeliveryTime", SqlDbType.VarChar).Value = DeliveryTime
        command.Parameters.Add("@UserID", SqlDbType.VarChar).Value = UserID
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Return Convert.ToBoolean(result)
    End Function

    Public Function GetListReturSO() As DataSet
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        Dim command As New SqlCommand
        Dim ds As New DataSet
        connection = New SqlConnection(Var.SUISConn)
        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.Text
        command.CommandText = "SELECT * FROM v_ListReturSO WHERE COMP = @Comp ORDER BY [Retur Nr.] DESC"
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        adapter = New SqlDataAdapter(command)
        adapter.Fill(ds)
        connection.Close()
        Return ds
    End Function

    Public Function SaveSampleRequest(ByVal Number As String, ByVal QuotationNumber As String, ByVal DocDate As String, _
                                        ByVal CustCode As String, ByVal Reff As String, _
                                        ByVal DeliveryAddress As String, ByVal DeliveryCity As String, ByVal DeliveryZip As String, _
                                        ByVal DeliveryCountry As String, ByVal DeliveryPhone As String, ByVal DeliveryFax As String, _
                                        ByVal Notes As String, ByVal AttentSal As String, ByVal AttentName As String, _
                                        ByVal UserID As String, ByVal Type As String) As String
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_SaveSampleRequest"
        command.Parameters.Add("@Number", SqlDbType.VarChar).Value = Number
        command.Parameters.Add("@DocDate", SqlDbType.VarChar).Value = DocDate
        command.Parameters.Add("@CustCode", SqlDbType.VarChar).Value = CustCode
        command.Parameters.Add("@QuotationNumber", SqlDbType.VarChar).Value = QuotationNumber
        command.Parameters.Add("@Reff", SqlDbType.VarChar).Value = Reff
        command.Parameters.Add("@DeliveryAddress", SqlDbType.VarChar).Value = DeliveryAddress
        command.Parameters.Add("@DeliveryCity", SqlDbType.VarChar).Value = DeliveryCity
        command.Parameters.Add("@DeliveryZip", SqlDbType.VarChar).Value = DeliveryZip
        command.Parameters.Add("@DeliveryCountry", SqlDbType.VarChar).Value = DeliveryCountry
        command.Parameters.Add("@DeliveryPhone", SqlDbType.VarChar).Value = DeliveryPhone
        command.Parameters.Add("@DeliveryFax", SqlDbType.VarChar).Value = DeliveryFax
        command.Parameters.Add("@Notes", SqlDbType.VarChar).Value = Notes
        command.Parameters.Add("@AttentSal", SqlDbType.VarChar).Value = AttentSal
        command.Parameters.Add("@AttentName", SqlDbType.VarChar).Value = AttentName
        command.Parameters.Add("@UserID", SqlDbType.VarChar).Value = UserID
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        command.Parameters.Add("@Type", SqlDbType.VarChar).Value = Type
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Return Convert.ToString(result)
    End Function

    Public Function SaveSampleRequestLine(ByVal Number As String, ByVal DocDate As String, ByVal CustCode As String, _
                                        ByVal Groups As String, ByVal Code As String, ByVal item_desc As String, _
                                        ByVal UnitUOM As String, ByVal UnitQty As String, ByVal DeliveryTime As String) As Boolean
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_SaveSampleRequestLine"
        command.Parameters.Add("@CustCode", SqlDbType.VarChar).Value = CustCode
        command.Parameters.Add("@DocDate", SqlDbType.VarChar).Value = DocDate
        command.Parameters.Add("@Number", SqlDbType.VarChar).Value = Number
        command.Parameters.Add("@Groups", SqlDbType.VarChar).Value = Groups
        command.Parameters.Add("@Code", SqlDbType.VarChar).Value = Code
        command.Parameters.Add("@item_desc", SqlDbType.VarChar).Value = item_desc
        command.Parameters.Add("@UnitUOM", SqlDbType.VarChar).Value = UnitUOM
        command.Parameters.Add("@UnitQty", SqlDbType.Decimal).Value = CDec(UnitQty)
        command.Parameters.Add("@DeliveryTime", SqlDbType.VarChar).Value = DeliveryTime
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Return Convert.ToBoolean(result)
    End Function

    Public Function PostingSampleRequest(ByVal Number As String) As Boolean
        Dim connection As SqlConnection
        Dim command As New SqlCommand
        connection = New SqlConnection(Var.SUISConn)

        connection.Open()
        command.Connection = connection
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "proc_PostingSampleRequest"
        command.Parameters.Add("@Number", SqlDbType.VarChar).Value = Number
        command.Parameters.Add("@Comp", SqlDbType.VarChar).Value = Var.CompID
        Dim result As Object = command.ExecuteScalar()
        connection.Close()
        Return Convert.ToBoolean(result)
    End Function
End Class
